package MyQueue;

public class leet_232 {
    public static void main(String[] args) {
        MyQueue_232 p = new MyQueue_232();
        p.push(1);
        p.push(2);
        p.push(3);
        p.push(4);

        int value = p.pop();
        System.out.println(value);

        p.push(5);
        value = p.pop();
        System.out.println(value);
        value = p.pop();
        System.out.println(value);
        value = p.pop();
        System.out.println(value);
        value = p.pop();
        System.out.println(value);


    }

}


class MyQueue_232 {
    // 尾指针
    private int size;
    // 数据存储
    private int[] queue;

    /** Initialize your data structure here. */
    public MyQueue_232() {
        this.size = 0;
        this.queue=new int[100];
    }

    /** Push element x to the back of queue. */
    public void push(int x) {
        this.queue[size]=x;
        this.size++;
    }

    /** Removes the element from in front of queue and returns that element. */
    public int pop() {
        if(this.size>0){
            int[] newQueue = new int[100];
            int value = this.queue[0];
            for(int i=1; i<this.size; i++){
                newQueue[i-1] = this.queue[i];
            }
            this.queue = newQueue;
            this.size--;
            return value;
        }
        return 0;
    }

    /** Get the front element. */
    public int peek() {
        if(this.size>0){
            int value = this.queue[0];
            return value;
        }
        return 0;
    }

    /** Returns whether the queue is empty. */
    public boolean empty() {
        if(size>0){return false;}
        return true;
    }
}

